﻿using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using MySqlConnector;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.Extensions.Logging;

public class MyContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }
    public DbSet<BlogHeader> Posts { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Blog>()
            .HasOne(e => e.Header)
            .WithOne(e => e.Blog)
            .HasForeignKey<BlogHeader>("BlogId");


        
    }

    protected override void OnConfiguring(DbContextOptionsBuilder options)
    {
        var mySqlConnection = new MySqlConnection("server=localhost;port=3306;database=test_asp;uid=root;pwd=rootroot;");
        options.UseMySql(mySqlConnection, MySqlServerVersion.LatestSupportedServerVersion)
            .LogTo(Console.WriteLine, LogLevel.Information);

    }
}

// Principal (parent)
public class Blog
{

    public int Id { get; set; }
    public string Title { get; set; }
    public BlogHeader Header { get; set; } // Reference navigation to dependent
}

// Dependent (child)
public class BlogHeader
{
    public int Id { get; set; }

    
    public Blog Blog { get; set; } 
}